package cn.leestudio.restlib.core;

import android.util.Log;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

class LoggingInterceptor implements Interceptor {
    private static final String TAG = LoggingInterceptor.class.getSimpleName();
       @Override  
       public Response intercept(Interceptor.Chain chain) throws IOException {
           Request request = chain.request();
           long t1 = System.nanoTime();  
           Log.d(TAG,String.format("Sending request %s on %nconnection -> %s%nheaders -> %s%n",request.url(), chain.connection(), request.headers()));
           Response response = chain.proceed(request);
           long t2 = System.nanoTime();
           Log.d(TAG,String.format("Received response for %s in %.1fms%nconnection=%s%ncode=%s",response.request().url(), (t2 - t1) / 1e6d, chain.connection(),response.code()));
           return response;  
       }  
   }  